package com.example.mvc.controller;

import com.example.mvc.bean.Book;
import com.example.mvc.bean.BookType;
import com.example.mvc.service.BookService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/addBookTypeServlet")
public class AddBookTypeServlet extends HttpServlet {
    BookService bookService = new BookService();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        BookType bookType = new BookType();
        bookType.setName(name);
        int count = bookService.addBookType(bookType);
        String contextPath = req.getContextPath();
        resp.sendRedirect(contextPath + "/bookTypeList");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

}
